/**
 * SignupAction.java 1.0 2007-4-25 ����12:00:55,���� by yangfan
 */


package org.in4j.bbs.action.user;

import org.in4j.bbs.action.AbstractAction;
import org.in4j.bbs.model.User;
import org.in4j.bbs.service.UserService;

/**
 * 注册用户
 * @author yangfan
 * @version 1.0 2007-4-25 ����12:00:55,����
 */
public class SignupAction extends AbstractAction
{
	private static final long serialVersionUID = 1L;

	private User user;
	private String confirmPassword;
	private UserService userService;
	private boolean agree_to_terms;

	public void setAgree_to_terms(boolean agree_to_terms)
	{
		this.agree_to_terms = agree_to_terms;
	}

	public User getUser()
	{
		return this.user;
	}

	public void setUser(User user)
	{
		System.out.println("setUser,user==>" + user);
		this.user = user;
	}

	public void setUserService(UserService userService)
	{
		this.userService = userService;
	}

	@Override
	public String doInput() throws Exception
	{
		System.out.println("agree_to_terms==>" + agree_to_terms);
		if(!agree_to_terms)
		{
			addFieldError("agree_to_terms", getText("bbs.front.user.reg.agree", "Sorry,you should agree the terms.Please chose \"I agree above of these terms\"."));
			return "pre_signup";
		}
		return INPUT;
	}

	@Override
	public void validate()
	{
		if(user != null && userService.getUserByName(user.getName()) != null)
			addActionError(getText("bbs.user.exists","Sorry,The username: ${user.name} is exists."));
	}

	@Override
	public String execute() throws Exception
	{
		userService.create(user);
		return SUCCESS;
	}

	public String getConfirmPassword()
	{
		return confirmPassword;
	}

	public void setConfirmPassword(String confirmPassword)
	{
		this.confirmPassword = confirmPassword;
	}
}
